package com.xiaoma.product.controller;

import com.xiaoma.product.entity.CategoryEntity;
import com.xiaoma.product.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.JwtUtils;
import utils.R;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @Author: xiaoma
 * @Date: 2021/7/8 14:31
 * @description:
 */
@RestController
@RequestMapping("product/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/queryAll2Tree")
    public R queryAll2Tree(){
       List<CategoryEntity> list = categoryService.queryAll2Tree();
       return R.ok().put("data",list);
    }
    @PostMapping("/delete")
    public  R delete(@RequestBody Long[] ids){
       Boolean flag =categoryService.removeMenuByIds(Arrays.asList(ids));
       return  flag?R.ok():R.error();
    }
    @PostMapping("/save")
    public  R save(@RequestBody CategoryEntity categoryEntity){
        boolean flag = categoryService.save(categoryEntity);
        return  flag?R.ok():R.error();
    }
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Long id){
        CategoryEntity data = categoryService.getById(id);
        return R.ok().put("data",data);
    }
    @PostMapping("/update")
    public  R update(@RequestBody CategoryEntity categoryEntity){
        boolean flag = categoryService.updateById(categoryEntity);
        return  flag?R.ok():R.error();
    }
}
